home *** CD-ROM | disk | FTP | other *** search
/ Commodore Free 27 / Commodore_Free_Issue_27_2009_Commodore_Computer_Club.d64 / beginning 12-2 < prev    next >
Text File  |  2023-02-26  |  11KB  |  375 lines

  1. ..
  2.  
  3.     In the Beginning Part 12
  4.      Lord Ronin from Q-Link
  5.  
  6.         CONTINUED FROM 12-1
  7.  
  8. Remember that when we discussed the
  9. Input and the Read stuff, there
  10. wasn't any way to get back or
  11. retrieve the inputted information? OK
  12. we never tried in the first place.
  13. The Commodore users guide is the one
  14. that brings up that subject. Well
  15. type in the following, while you
  16. still have the above program in
  17. memory.
  18.  
  19. FOR A= 1 TO 5: ?B(A);:NEXT
  20.  
  21. The reason that I asked you to type
  22. in the amount of numbers as 5 and
  23. those specific numbers. Simply is to
  24. illustrate the point of this line. 
  25. You will see on the screen...
  26.  
  27. 125    167    189    167    158
  28.  
  29. The numbers that you typed in for
  30. this example. See they are stored.
  31. Now try out the programme again and
  32. use your own amount and numbers. Then
  33. adjust the line above. Note it isn't
  34. a line number, just something you can
  35. type in on the screen. Alter the 1 to
  36. what ever you chose for the amount.
  37. Then see what happens.
  38.  
  39. Welcome now to DIMARRAYS. Well they
  40. say Dimension on page 98. But I am
  41. cutting to the chase here. Because as
  42. soon as you tried more than 10
  43. numbers in the above example you got
  44. an error. Probably said "DIMENSION
  45. ERROR". Makes you wonder what sci-fi
  46. movie you entered. You can only have
  47. 11 <0 to 10> elements in a one
  48. dimensional array. OK add the
  49. following to the programme.
  50.  
  51. 5 dim b(100)
  52.  
  53. You just told the C= that you will
  54. have a maximum of 100 things, or
  55. elements in the array. Can be bigger,
  56. I am not going to say how big at this
  57. time. But it is BIG. Better to make
  58. several different DimArrays than one
  59. gigantic one. OK I'll confess the
  60. maximum that you can put in a
  61. DimArray is <hold onto your hats>
  62. 32767. If you do, your program is
  63. bulky and will be very slow.
  64.  
  65. OK then lets run that program with
  66. the new line 5. Then we are going to
  67. change it to...
  68.  
  69. 5<press return>
  70.  
  71. Right that kills the line
  72. completely. Have to do that to enter
  73. this one.
  74.  
  75. 15 dim b(x)
  76.  
  77. Now what ever x is will be the
  78. number of elements in the dim array.
  79. Note here is that once an array has
  80. been <dim>ensioned. It can not be
  81. redone in another part of the
  82. programme. However you can have more
  83. than one dim array in a programme and
  84. even on the same line. Following is
  85. just an example, NOT a line to type
  86. in!
  87.  
  88. 10 dim c(20),d(50),e(40)
  89.  
  90. Soon we are going to type in a new
  91. programme. But first this is
  92. something that isn't in the users
  93. manual. Comes from a book that
  94. teaches making text adventure games.
  95. Put the DIM ARRAYS at the start or as
  96. close to the start of your programme
  97. as possible. That Commodore users
  98. guide uses several dim arrays for the
  99. games. These are all "declared" in
  100. the first several lines of the
  101. programme. Though defined a bit later
  102. in the programme.
  103.  
  104. An example from a programme that I
  105. modified. No it isn't really that
  106. impressive, remember I am a lamer at
  107. this stuff. I just used some of the
  108. things that we have or will cover in
  109. this users manual. Well the program
  110. is one that I saved from Q-Link. Done
  111. in Basic and it for the creation of
  112. 1st edition of Advanced Dungeons &
  113. Dragons monsters. Saved it to disk
  114. and printed it out. I did a few
  115. things to it, such as adding some
  116. stats. Those where different
  117. variables, and we covered them
  118. already. What I did that applies to
  119. this part of the series, is that I
  120. created a Dim Array. Originally,
  121. after you typed in the stats for the
  122. monster for your game. You could
  123. write a description. However the
  124. author made a one dimensional array.
  125. Meaning that I had only 11 lines max
  126. for a description of the monster and
  127. its habits. Not enough when I am
  128. copying them out of old and crumbling
  129. magazines that are over 25 years old.
  130. What I did was simply turn that into
  131. a Dim Array looking like DIM C(40). C
  132. being the existing variable. Now I
  133. have many more lines for a
  134. description. See it isn't that
  135. fantastic. Just a simple re-write of
  136. one line. Oh yeah that was in the
  137. first 15 or so lines of
  138. programming/code.
  139.  
  140. new
  141. 1 rem dice simulation:?"<shift
  142. clearhome>"
  143. 10 input"how many rolls:";x
  144. 20 forl=1tox
  145. 30 r=int(6*rnd(1))+1
  146. 40 f(r)=f(r)+1
  147. 50 nextl
  148. 60 ?"face","number of times"
  149. 70 forc=1to6:?c,f(c):next
  150.  
  151. Running this and you will get a list
  152. on the left of the faces of a D6 <6
  153. sided die> and the number of times
  154. that face appeared out of the total
  155. number of times that you entered for
  156. the number of rolls. F(R) is the
  157. array for the random number generator
  158. in line 30. L is the variable for the
  159. number of times the die is to be
  160. rolled. Line 70 has the C= 1 to 6
  161. Then it wants the value of C printed.
  162. The faces on the left of the screen.
  163. But see that next there is the array
  164. of F(C). Bit confusing as the
  165. explanation in the Commodore users
  166. guide is short and lacking in depth.
  167. My understanding, and it is quite
  168. possibly wrong, is that the F(R) is
  169. the array for the number of times and
  170. the F(C) is the array for that number
  171. for each face or side of the die.
  172.  
  173. They next turn the page to 100 and
  174. show the same programme using IF THEN
  175. statements. Doubles in the number of
  176. lines used. More than double in the
  177. space in the computer that would be
  178. used.
  179.  
  180. TWO-DIMENSIONAL ARRAYS is the title
  181. for the next part. They start off
  182. with showing us what it would look
  183. like Z(4,6) is a two dimensional
  184. array. First part is the array name
  185. and the other two parts separated by
  186. the, symbol are the subscripts.
  187. Written out in a matrix type box with
  188. the following value of Z(3,4)=71would
  189. look like the following in the above
  190. defined two dim array.
  191.  
  192.  
  193.    0   1   2   3   4   5   6
  194. 0  -   -   -   -   -   -   -
  195.  
  196. 1  -   -   -   -   -   -   -
  197.  
  198. 2  -   -   -   -   -   -   -  
  199.  
  200. 3  -   -   -   -  71   -   -
  201.  
  202.  
  203. First subscript is sort of the row
  204. and the second one is sort of the
  205. column. You can get the idea that
  206. there can now be a lot more installed
  207. than before. OK there are some rules
  208. to follow in creating a two dim
  209. array.
  210.  
  211. Gotta dim the array: dimZ(4,6) as
  212. the first part. That sets up the
  213. areas for use. Next you need to
  214. assign the data that is going into
  215. the array sort of like: Z(3,4)=71.
  216. Next assign the values to other
  217. variables like: ZB=Z(1,1). Then print
  218. the values. Complex, confusing it
  219. doth sound at this point. Trust me
  220. that I dig that part, no not the
  221. variable thing, that it is complex
  222. and confusing. This is not something
  223. you can get in one sitting. Takes
  224. several goings over, and other
  225. sources of information to slowly
  226. click. Then you ask yourself why you
  227. didn't catch it at the start, since
  228. it is so simple. Or so I have been
  229. told. I'm still at the part of the
  230. light is just turning on for these
  231. arrays. My advice is to just ride
  232. this part for now. Work on the ideas
  233. as you feel comfortable. Now then
  234. lets move onto a type in example.
  235.  
  236. new
  237.  
  238. 20 ?"<shifted clear home>"
  239. 30 forr=1to4
  240. 40 ?"Question # : ";r
  241. 50 ?" 1-yes  2-no  3-undecided"
  242. 60 ?"what was the response : ";
  243. 61 getc:ifc,1orc>3then61
  244. 65 ?c:?
  245. 70 a(r,c)=a(r,c)+1
  246. 80 nextr
  247. 85 ?
  248. 90 ?"do you want to enter
  249. another":?"response (y/n)";
  250. 100 geta$:ifa$=22then100
  251. 110 ifa$="y"then20
  252. 120 ifa$<>"n"then100
  253. 130 ?"<sifted clear home>";"the total
  254. responses were:":?
  255. 140 ?spc(18);"responce"
  256. 141
  257. ?"question","yes","no","undecided"
  258. 142 ?"--------
  259. -----------------------------"
  260. 150 ?r=1to4
  261. 160 ?r,a(r,1),a(r,2),a(r,3)
  262. 170 nextr
  263.  
  264. Give it a run and see what happens.
  265. You end up with 4 questions. Well not
  266. exactly, since they are never stated
  267. as what is the question. Then you
  268. have a choice of one out of 3 for a
  269. reply to each of the 4. This is going
  270. to be tabulated at the end with how
  271. many times each of the possible three
  272. answers were given for each of the 4
  273. questions. Line 142 is a bit of a
  274. problem in getting the - lines
  275. correct. Don't worry if you flubbed
  276. that one. I always do myself. Line
  277. 140 has a spc(18). That takes the
  278. writing to the 18th space on the row.
  279. Those comma things in line 141, space
  280. out by 10 remember. Making columns
  281. for the final print out on the
  282. screen. 100-120 is our simple get a
  283. reply from the kb. In fact most of
  284. this we have seen and done in some
  285. form already.
  286.  
  287. The Commodore users guide covers this
  288. entire programme in three paragraphs,
  289. and that is on one page, with a
  290. quarter of the page blank and a chart
  291. at the top of the page. Right; not a
  292. lot of data for you to read and learn
  293. how this all works. That is something
  294. I was recently talking about on the
  295. some IRC chats, how it is easier to
  296. learn with others than by yourself,
  297. and the lack of in-depth information
  298. in the user's manual. Before the
  299. comments though, lets look at the
  300. array stuff in this programme.
  301.  
  302. Really the array stuff is the new
  303. part. We see an array at line 70. BTW
  304. that will update the element. So says
  305. the rem statement on that line in the
  306. Commodore users guide. What type of
  307. array is it? That is a bit harder to
  308. see. A(R,C) this tells us it is a two
  309. dimensional array. Because of the two
  310. elements inside. But now then, what
  311. are the parameters of these elements?
  312. That takes a little bit of looking at
  313. the programme. In the array of A(R,C)
  314. we look through the programme and see
  315. that the R is in line 30, and is for
  316. the number of questions. There are 4
  317. questions or 4 elements. That makes
  318. the R=4, so A(4,C) is what we have so
  319. far. Line 61 sets up the ends for C
  320. being 1-3. OK that must be the yes
  321. and no and undecided part. Line 65
  322. prints c. C then is 3 and that means
  323. our array of A(R,C) is A(4,3). Right
  324. a 4 by 3 two dimensional array. At
  325. this point it is important to know
  326. that the first row and column of
  327. A(0,0), or the first row and column
  328. of any array is mainly never used. So
  329. is the impression from the Commodore
  330. users guide. Line 160 prints the
  331. values, the values of the elements in
  332. A(R,1) A(R,2) and A(R,3) The numbers
  333. for the yes, no and undecided. Yeah
  334. it is confusing and complicated at
  335. the start. I honestly at this time am
  336. still learning this section.
  337.  
  338. Outro will have some more statements
  339. on this part. Last of the Commodore
  340. users guide now. Appendices and these
  341. are a list of accessories for the 64,
  342. Advanced Cassette Operation, Basic
  343. term explanation, Key abbreviations,
  344. Screen Codes, Ascii & CHR$ codes,
  345. Memory Maps, Math functions,
  346. Printouts, Programmes to try out,
  347. Basic conversion, Error Message,
  348. Musical notes, and if you have a copy
  349. and are lucky. There is a quick
  350. reference card at the end. May you
  351. find a copy and with this series,
  352. have some fun in programming.
  353.  
  354. COMMODORE FREE
  355. I tried to put the Commodore Users
  356. Guide into the Loadstar Quick menu,
  357. you can download a copy from the
  358. website www.commodorefree.com
  359.  
  360. Because of the size I had to split the
  361. manual into 2 d64 images:
  362.  
  363.   http://www.commodorefree.com/
  364.    tools/guide/guide1.zip
  365.  
  366.   http://www.commodorefree.com/
  367.    tools/guide/guide2.zip
  368.  
  369. The text is taken from Project 64
  370. version of the user guide in plain
  371. text so many of the diagrams are
  372. converted to text art.
  373.  
  374.  END
  375.